1 module hip.api.input.inputmap;
2 public import hip.api.input.gamepad;
3 public import hip.math.vector;
4 
5 /**
6  * Example of an inputmap data format:
7 
8 ```json
9 {
10     "actions": {
11         "run": {
12             "gamepad": ["psCross"]
13         }
14     },
15     "directionals": {
16         "move": {
17             "x": [
18                 {"keyboard": "a", "gamepad": "dPadLeft", "value": -1},
19                 {"keyboard": "d", "gamepad": "dPadRight","value": 1},
20                 {"analog": "left", "axis": "x"}
21             ],
22             "y": [
23                 {"keyboard": "w", "gamepad": "dPadUp", "value": -1},
24                 {"keyboard": "s", "gamepad": "dPadDown", "value": 1},
25                 {"analog": "left", "axis": "y"}
26             ]
27         }
28     }
29 }
30 ```
31  */
32 interface IHipInputMap
33 {
34     struct Context
35     {
36         ///Got from the object that contains input information
37         string name;
38         ///Got from the "keyboard" properties from input json
39         char[] keys;
40         ///Got from "gamepad" properties from input json
41         HipGamepadButton[] btns;
42     }
43     struct AxisContext
44     {
45         /**
46          * Holds whether this controls the X, Y or Z axis.
47          * May also hold which analog stick, either the left or right on it, if that happens, it can't hold
48          * a key, value nor button.
49          * Then, also hold which axis from the analog is being mapped
50          */
51         ubyte axis;
52         /**
53          * Holds which gamepad button holds the value specified
54          */
55         HipGamepadButton btn;
56         /**
57          * A keyboard key
58          */
59         char key;
60         /**
61         * Value ranging from byte.min - byte.max
62         * A float value is usually specified on input mapping, between 1.0 and -1.0
63         * This value is then scaled by 127
64         */
65         byte value;
66     }
67     void registerInputAction(string actionName, Context ctx);
68     float isActionPressed(string actionName);
69     float isActionJustPressed(string actionName);
70     float isActionJustReleased(string actionName);
71     /**
72      * Gets a Vector3 from a mapped directional.
73      * Params:
74      *   directionalName = A directional which was registered through "directionals" on input map json
75      * Returns:
76      */
77     Vector3 getAxis(string directionalName);
78 }